package com.xm.controller;

import com.xm.common.entity.R;
import com.xm.service.FeignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Author lililiang
 * @Date 21/04/29 09:57
 * @Version 1.0
 **/
@Api("订单管理")
@RestController
@Slf4j
@RequestMapping("order")
@RefreshScope //支持Nacos的动态刷新功能。
public class OrderController {

    /**
     * @return java.lang.String
     * @Description 直接访问返回字符串
     * @Author lililiang
     * @Date 11:09 21/04/29
     * @Param [id]
     **/
    @ApiOperation("返回字符串")
    @GetMapping("getOrder/{id}")
    public String get(@PathVariable("id") Integer id) {
        log.info("order-get, id:" + id);
        return "order-get, id:" + id;
    }

    @Resource
    private RestTemplate restTemplate;

    //    @Value("${service-url.nacos-user-service}")
    private String serverURL;

    /**
     * @return java.lang.String
     * @Description 使用Ribbon组件，order调用pay，测试负载均衡
     * @Author lililiang
     * @Date 11:09 21/04/29
     * @Param [id]
     **/
    @ApiOperation("返回字符串-Ribbon")
    @GetMapping(value = "/getOrderRibbon/{id}")
    public String paymentInfo(@PathVariable("id") Long id) {
        return restTemplate.getForObject(serverURL + "/pay/getPay/" + id, String.class);
    }


    //    @Value("${config.info}")
    private String configInfo;

    /**
     * @return java.lang.String
     * @Description 获取动态配置信息
     * @Author lililiang
     * @Date 11:09 21/04/29
     * @Param [id]
     **/
    @ApiOperation("获取配置")
    @GetMapping(value = "/getConfig")
    public String getConfig() {
        return configInfo;
    }

    @Resource
    private FeignService feignService;

    @ApiOperation("获取数据库")
    @GetMapping(value = "getPayFormDataBase/{id}")
    public R getPayFormDataBase(@PathVariable("id") Long id) {
        return feignService.getPayFormDataBase(id);
    }

}
